package com.sinosoft.dsp.platform.components.portal.iteration;

import java.util.List;

import org.primefaces.model.DefaultTreeNode;

import com.sinosoft.dsp.system.core.log.Log;
import com.sinosoft.dsp.system.utils.Const;

public abstract class SinoAbstractLazyTreeViewBean<T extends ISinoTreeDataObject>
		extends SinoAbstractTreeViewBean<T> implements ISinoLazyTreeViewBean<T> {

	private static final Log log = Log
			.getLog(SinoAbstractLazyTreeViewBean.class.getName());

	/**
	 * 在该方法中不使用
	 */
	@Override
	public List<T> load() {
		return null;
	}

	/**
	 * 重新构建树
	 */
	protected void reload() {
		clear();
		try {
			List<T> dirList = loadFirstLevelNodes();
			if (dirList != null)
				addRows(dirList);
		} catch (Exception e) {
			log.error("加载结构数据出现错误");
		}
	}

	/**
	 * 创建节点
	 * 
	 * @param t
	 * @return
	 */
	protected DefaultTreeNode createNode(T t) {
		DefaultTreeNode node = new SinoLazyTreeNode<T>(this);
		if (Const.isEmpty(t.getType())) {
			t.setType(ISinoTreeDataObject.TREE_TYPE_LEAF);
		} else {
			node.setType(t.getType());
		}
		node.setData(t);
		return node;
	}

	@Override
	public boolean isDynamic() {
		return true;
	}

}
